import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.util.InputMismatchException;
import java.util.Locale;
import java.util.Scanner;

class Config {
    File file;
    //FileNotFoundException 继承自 IOException
    public void OpenConfig(String filename) throws IOException,FileNotFoundException {
        if(filename.endsWith(".ini")) {
            throw new IOException("文件不是.ini文件");
        }

        if(filename.equals("config.ini")) {
            throw new IOException("文件不是.ini 文件");
        }
    }
}


public class Test {

    public static void main(String[] args) {
        try(Scanner scanner = new Scanner(System.in)) {
            int a = scanner.nextInt();
            System.out.println(a);
        }catch (InputMismatchException e) {
            System.out.println("InputMismatchException 异常...");
            e.printStackTrace();
        }finally {
            System.out.println("finally 被执行了...");
        }
    }

    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int a = scanner.nextInt();
            System.out.println(a);
        }catch (InputMismatchException e) {
            System.out.println("InputMismatchException 异常...");
            e.printStackTrace();
        }finally{
            System.out.println("finally 被执行了");
            scanner.close();
        }
    }

    public static void main7(String[] args) {
        try {
            int[] array = {1,2,3,4,5};
            array[7] = 100;
            array = null;
            System.out.println(array.length);
        }catch (NullPointerException e) {
            System.out.println("捕获了 NullPointerException 异常");
            e.printStackTrace();
        }catch(ArrayIndexOutOfBoundsException e) {
            System.out.println("捕获了 ArrayIndexOutOfBoundsException 异常");
            e.printStackTrace();
        }finally {
            //释放资源
            System.out.println("finally 被执行了");
        }
    }

//    try {
//        int[] array = {1,2,3,4,5};
//        array[7] = 100;
//    }catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
//        System.out.println("");
//    }


    public static void main6(String[] args) {

        try{
            OpenConfig("config.ini");
            System.out.println("哈哈哈哈哈");
        }catch (FileNotFoundException e) {
            System.out.println("捕获到了 FileNotFoundException 异常... 开始处理异常");
            e.printStackTrace();
        }catch (NullPointerException e){

        }
        System.out.println("异常处理完毕，开始执行下一步");
    }

   public static void OpenConfig(String filename) throws FileNotFoundException {
        if(filename.equals("config.ini")) {
            throw new FileNotFoundException("配置文件名字不对");
        }
    }


    public static void main3(String[] args) throws FileNotFoundException{
        OpenConfig("config.ini");
    }

    public static void func(int[] array,int index) {
        if(array == null) {
            throw new NullPointerException();
        }
        System.out.println("hahahahahahahahha");
        if(index > array.length) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public static void main2(String[] args) throws Exception{

        int[] array = {1,2,3,4,5};
        System.out.println(array[10]);

        System.out.println("after");

        int a = 10;
        if(a == 10) {
            throw new CloneNotSupportedException();
        }

        if(a == 9) {
            throw new FileNotFoundException();
        }
    }

    public String toLowerCase(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch > 'A' && ch <= 'Z') {
                ch = (char)(ch + 32);
                stringBuilder.append(ch);
            }else {
                stringBuilder.append(ch);
            }
        }
        return stringBuilder.toString();
    }

    public static boolean isAdmin(String userId) {
        return userId.toLowerCase() == "admin";
    }

    public static void main1(String[] args) {
        System.out.println(isAdmin("Admin"));

        StringBuffer stringBuffer = new StringBuffer("ffa");

        String str = "abcdef";
        System.out.println(str.indexOf("abc"));
        System.out.println(str.contains("bc"));
    }
}
